
int foodClerkLineLock;
int foodClerkLineConditionVariables[5];
int foodClerkLocks[5];
int foodClerkConditionVariables[5];

int foodClerkLineCount[5];
int foodEarnings[5];
enum ClerkStateEnum foodClerkStates[5];

int popcornBeingSold[5];
int sodaBeingSold[5];
int foodTotal[5];

/* Number of foodclerk locks */
int numberOfFoodClerksLock;

/* numberOfFoodClerks*/
int numberOfFoodClerks;

void FoodClerk(/*int clerkNumber*/)
{
	int clerkNumber;

	/*waits movie theater so that everything will only start when their data has been initialized*/
	/*LockAcquire(initialLock);
	LockRelease(initialLock);*/
	
	LockAcquire(numberOfFoodClerksLock);
	clerkNumber = numberOfFoodClerks;
	numberOfFoodClerks++;
	LockRelease(numberOfFoodClerksLock);

	
	while(1)
	{
onBreak:


		LockAcquire(foodClerkLineLock);
		LockAcquire(foodClerkLocks[clerkNumber]);
		if(foodClerkStates[clerkNumber]==on_break)
		{
			/*printf("%s %i going on break\n",currentThread->getName(),clerkNumber);*/
		}
		
		/*for(int i=0;foodClerkStates[clerkNumber]==on_break;i++)
		{
			currentThread->Yield();
			if(i==BREAK_LENGTH)
			{
				printf("%s %i coming off of break\n",currentThread->getName(),clerkNumber);
				foodClerkStates[clerkNumber]=available;
			}
		}*/
		if(foodClerkStates[clerkNumber]!=on_break)
		{
			
			if(foodClerkLineCount[clerkNumber]>0)	/*If there is a line*/
			{
				Write1("Food Clerk %i has a line length ",32,1,clerkNumber);
				Write1("%i and is signaling a customer\n",53,1,foodClerkLineCount[clerkNumber]);
				/*
				foodClerkLineConditionVariables[clerkNumber]->Signal(foodClerkLineLock);	/*Wake up the first person in line*/
				Signal(foodClerkLineConditionVariables[clerkNumber],foodClerkLineLock);
				foodClerkLineCount[clerkNumber]--;	/*decrease the line size*/
				foodClerkStates[clerkNumber]=busy;	/*make myself busy*/
			}
			else					/*If there isn't a line*/
			{
			Write1("Food Clerk %i has no line. I am available for a customer\n",58,1,clerkNumber);
				foodClerkStates[clerkNumber]=available;	/*Set myself available*/
			}
			
		}
		LockRelease(foodClerkLineLock);
		Wait(foodClerkConditionVariables[clerkNumber], foodClerkLocks[clerkNumber]);
		LockAcquire(foodClerkLocks[clerkNumber]);
		if(foodClerkStates[clerkNumber]==on_break)
		{
			goto onBreak;
		}

		/*Acknowledge Order*/
		Write1("Food Clerk %i confirming popcorn order\n",40,1,clerkNumber);
		Signal(foodClerkConditionVariables[clerkNumber],foodClerkLocks[clerkNumber]);
		/*Wait for more*/
		Wait(foodClerkConditionVariables[clerkNumber],foodClerkLocks[clerkNumber]);
		
		
		
		LockAcquire(foodClerkLocks[clerkNumber]);
		/*calculate total*/
		foodTotal[clerkNumber]=popcornBeingSold[clerkNumber]*5+sodaBeingSold[clerkNumber]*4;
		
		Write1("Food Clerk %i has an order for ",31,1,clerkNumber);
		Write1("%i popcorn and ",15,1,popcornBeingSold[clerkNumber]);
		Write1("%i soda. The cost is ",21,1,sodaBeingSold[clerkNumber]);
		Write1("%i.\n",5,1,foodTotal[clerkNumber]);
		
		/*Give Order*/
		Signal(foodClerkConditionVariables[clerkNumber],foodClerkLocks[clerkNumber]);
		/*Wait for payment*/
		Wait(foodClerkConditionVariables[clerkNumber],foodClerkLocks[clerkNumber]);
		
		Write1("Food Clerk %i has been paid for the order\n",43,1,clerkNumber);
		Signal(foodClerkConditionVariables[clerkNumber],foodClerkLocks[clerkNumber]);


	}
}


